package com.bolt.report.engine.fill;

import com.bolt.common.utils.StrUtil;
import com.bolt.report.definition.CellDefinition;
import com.bolt.report.engine.BindData;
import com.bolt.report.engine.FillElementVisitor;
import com.bolt.report.engine.export.Exporter;

public class FillImageElement extends BaseFillElement<String> {


    private int width;

    private int height;

    private int wholeWidth;

    private int wholeHeight;

    private String expr;

    private BindData bindData;

    private String imageType;

    private FillContext fillContext;

    public FillImageElement(CellDefinition element,  FillContext fillContext) {
        this.value = element.getImg();
        this.fillContext = fillContext;
        this.width = element.getWidth();
        this.height = element.getHeight();
        this.wholeWidth = element.getCellWidth();
        this.wholeHeight = element.getHeight();
    }



    public FillImageElement(CellDefinition element, BindData bindData, FillContext fillContext) {
        this.value = element.getImg();
        this.bindData = bindData;
        this.expr = element.getExpression();
        this.fillContext = fillContext;
        this.width = element.getWidth();
        this.height = element.getHeight();
        this.wholeWidth = element.getCellWidth();
        this.wholeHeight = element.getHeight();
    }


    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }



    public void setExpr(String expr) {
        this.expr = expr;
    }



    public BindData getBindData() {
        return bindData;
    }

    public void setBindData(BindData bindData) {
        this.bindData = bindData;
    }

    public String getImageType() {
        if (StrUtil.isNotBlank(this.getValue())) {
            String imageHead = StrUtil.subBefore(this.getValue(), ";", false);
            imageType = StrUtil.subAfter(imageHead, "/", true);
        }
        return imageType;
    }

    public FillContext getFillContext() {
        return fillContext;
    }

    public int getWholeWidth() {
        return wholeWidth;
    }

    public void setWholeWidth(int wholeWidth) {
        this.wholeWidth = wholeWidth;
    }

    public int getWholeHeight() {
        return wholeHeight;
    }

    public void setWholeHeight(int wholeHeight) {
        this.wholeHeight = wholeHeight;
    }

    @Override
    public <T> void accept(FillElementVisitor<T> visitor, T arg) {
        visitor.visit(this, arg);
    }

    @Override
    public <E extends Exporter> void accept(ExporterVisitor<E> visitor, E exporter)  {
        visitor.visit(this,exporter);
    }
}